package com.tl.commonlibrary.ui.adapter;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;

import java.util.List;

/**
 * Created by jiangzhongshan on 18/2/4.
 */

public class ListViewAdapter<T> extends IAdapter<T> {
    private OnListViewAdapterListener listViewAdapterListener;

    public ListViewAdapter(Context context, List datas, int layoutId, OnListViewAdapterListener<T> listViewAdapterListener) {
        super(context, datas, layoutId);
        this.listViewAdapterListener = listViewAdapterListener;
    }

    public ListViewAdapter(Context context, List datas, int[] mLayoutIds, OnListViewAdapterListener<T> listViewAdapterListener) {
        super(context, datas, mLayoutIds);
        this.listViewAdapterListener = listViewAdapterListener;
    }

    public OnListViewAdapterListener getListViewAdapterListener() {
        return listViewAdapterListener;
    }

    public void setListViewAdapterListener(OnListViewAdapterListener listViewAdapterListener) {
        this.listViewAdapterListener = listViewAdapterListener;
    }

    @Override
    protected void getView(ViewHolder viewHolder, T entity, int position, View convertView, boolean isConvert, int itemViewType, ViewGroup parent) {
        if (listViewAdapterListener != null) {
            listViewAdapterListener.getView(viewHolder, entity, position, convertView, isConvert, itemViewType, parent);
        }
    }

    @Override
    public void onClick(View v) {
        if (listViewAdapterListener != null) {
            listViewAdapterListener.onClickViewInListItem(v);
        }
    }

    public interface OnListViewAdapterListener<T> {
        void onClickViewInListItem(View v);

        void getView(ViewHolder viewHolder, T entity, int position, View convertView, boolean isConvert, int itemViewType, ViewGroup parent);
    }
}
